﻿
@{
    ViewBag.Title = "中选与非中选对照";
    List<NCP.Model.GroupPurchase> list = ViewData["gplist"] as List<NCP.Model.GroupPurchase>;
}


<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">

                    <label class="layui-form-label">批次筛选</label>
                    <div class="layui-input-inline" style="width:100px">
                        @*@Html.RelGroupPurchaseSelect("GroupPurchase", "")*@
                        
                            <select id="setpc" name="setpc" lay-filter="setpc"  lay-verify="required" lay-search>
                                <option value="0">全部</option>
                                <option value="1">正在执行</option>
                                <option value="2">已到期</option>
                            </select>
                        
                    </div>
                </div>
                <div class="layui-inline">

                    <label class="layui-form-label">集采批次</label>
                    <div class="layui-input-inline" style="width:250px">
                        @*@Html.RelGroupPurchaseSelect("GroupPurchase", "")*@
                        <select name="GroupPurchase" id="GroupPurchase" lay-filter="GroupPurchase" lay-verify="required">
                            <option value="">请选择集采批次</option>
                            @foreach (var item in list)
                            {
                                <option value=@item.Code>@item.Year @item.Name</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-inline">

                    <label class="layui-form-label">药品</label>
                    <div class="layui-input-inline" style="width:200px">
                        @*@Html.RelDrugSelect("drugCode", "")*@
                        <select name="drugCode" id="drugCode" lay-verify="required" lay-search>
                            <option value="">请选择药品</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">数据维护:</label>
                    <div class="layui-input-inline" style="width:100px">
                        <select id="set" lay-verify="required" lay-search>
                            <option value="">请选择</option>
                            <option value="1">已维护</option>
                            <option value="2">未维护</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" style="margin-left:20px; padding:0 25px;" id="btnQuery"> 查 询 </button>
                </div>
                <div class="layui-inline">

                    <button class="layui-btn" style="margin-left:10px; padding:0 5px;" id="doImportfzx"> 选择非中选文件</button>
                    <button class="layui-btn" style="margin-left:10px; padding:0 5px;" id="Importfzx"> 导入非中选</button>
                    <button class="layui-btn" style="margin-left:10px; padding:0 5px;" id="doDownloadfzx"> 非中选模板下载 </button>
                    <!-- <button class="layui-btn" style="margin-left:10px; padding:0 5px;" id="doImporttpz"> 选择同品种文件</button>
     <button class="layui-btn" style="margin-left:10px; padding:0 5px;" id="Importtpz"> 导入同品种</button>
     <button class="layui-btn" style="margin-left:10px; padding:0 5px;" id="doDownloadtpz"> 同品种模板下载 </button>-->
                    <button class="layui-btn" style="margin-left:10px; padding:0 5px;" id="export"> 导出非中选药品 </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            
            <table id="LAY-dept-list" lay-filter="LAY-dept-list"></table>
            <script type="text/html" id="barBtn">

                <button class="layui-btn layui-btn-sm" lay-event="drug">非中选药品维护</button>
                <!--  <button class="layui-btn layui-btn-sm" lay-event="vdrug">同品种药品维护</button>-->
            </script>
            </div>
        </div>
    </div>


    <script src="../layuiadmin/layui/layui.js"></script>
    <script type="text/javascript" src="~/Scripts/jsonDB.js"></script>
    <script type="text/javascript">
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
            }).use(['index', 'table', 'admin' ,'upload'], function () {
            var table = layui.table
                , form = layui.form
                , $ = layui.$
                , admin = layui.admin
                , util = layui.util
                    , upload = layui.upload;

            RenderData();
            initTableBtn(table);
                var aa = "";

            //监听行工具事件
            table.on('tool(LAY-dept-list)', function (obj) {
                var data = obj.data;

                if (obj.event === 'drug') {
                    layer.open({
                        type: 2
                        , title: '非中选药品维护'
                        , content: '/GroupChoseDrugCompare/ChoseDrugCompare?gpCode=' + data.GpCode + '&drugcode=' + data.ChosedrugCode + '&drugname=' + data.ChosedrugName + '&Specs=' + data.Specs + '&Enabled=' + data.Enabled
                        , area: ["1200px", "600px"]
                        , maxmin: true
                    });
                }
                else if (obj.event === 'vdrug') {
                        layer.open({
                            type: 2
                            , title: '同品种药品维护'
                            , content: '/GroupChoseDrugCompare/GroupVarietyDrugCompare?gpCode=' + data.GpCode + '&drugcode=' + data.ChosedrugCode + '&drugname=' + data.ChosedrugName + '&Specs=' + data.Specs + '&Enabled=' + data.Enabled
                            , area: ["1200px", "600px"]
                            , maxmin: true
                        });
                }
            });


            //监听集采批次下拉框
            form.on('select(GroupPurchase)', function (data) {
                var type = data.value;
                aa = type;
                //console.log(type);
                $.ajax({
                    type: 'post',
                    url: '/GroupChoseDrugCompare/GetChoseDrugInfo',
                    data: "gpcode="+type,
                    //dataType: 'json',
                    success(res) {
                        var str = '<option value="">请选择药品</option>';
                        for (var i in res) {
                            str += "<option value='" + res[i].DrugCode + "'>" + res[i].DrugName+ " " + res[i].Specs +"</option>";
                        }
                        $('#drugCode').html(str)
                        form.render();
                    }
                })
                //console.log(data)
            });
                //监听批次筛选下拉框
                form.on('select(setpc)', function (data) {
                    var type = data.value;
                    aa = type;
                    //console.log(type);
                    $.ajax({
                        type: 'post',
                        url: '/GroupChoseDrugCompare/GetGroupInfo',
                        data: "param=" + type,
                        //dataType: 'json',
                        success(res) {
                            var str = '<option value="">请选择集采批次</option>';
                            for (var i in res) {
                                str += "<option value='" + res[i].Code + "'>" + res[i].Year + " " + res[i].Name + "</option>";
                            }
                            $('#GroupPurchase').html(str)
                            form.render();
                        }
                    })
                    //console.log(data)
                });
            //监听单元格编辑
            //table.on('edit(LAY-dept-list)', function (obj) {
            //    var value = obj.value //得到修改后的值
            //        , data = obj.data //得到所在行所有键值
            //        , field = obj.field; //得到字段
            //    layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改值为：' + util.escape(value));
            //});

            //table.on('edit(LAY-dept-list)', function (obj) {
            //    let value = obj.value // 得到修改后的值
            //        , data = obj.data // 得到所在行所有键值
            //        , field = obj.field; //得到修改的字段
            //    let modifiedData = { id: data.id };
            //    modifiedData[field] = value;
            //    $.ajax({
            //        type: "POST",
            //        contentType: "application/json;charset=UTF-8",
            //        url: serverBase + 'newsType/update',
            //        data: JSON.stringify(modifiedData),
            //        dataType: 'json',
            //        success: function (res) {
            //            if (!handleResponseData(res, layer)) {
            //                setTimeout(function () {
            //                    location.href = 'newsTypeList.html';
            //                }, delayTime);
            //            }
            //        }
            //    });
            //});

            $(document).ready(function () {
                $("#btnQuery").click(function () {
                    RenderData("2");
                });


            });
                //上传数据
                    upload.render({ //允许上传的文件后缀
                        elem: '#doImportfzx'
                        , url: '/GroupChoseDrugCompare/ImportUnchoseDrug'//此处配置你自己的上传接口即可
                        , accept: 'file' //普通文件
                        , exts: 'xls|xlsx' //只允许上传表格文件
                        , auto: false//不自动上传
                        , bindAction: '#Importfzx'
                        , before: function () {
                                this.data = {
                                    gpCode: $("#GroupPurchase").val()
                                }
                        }

                        , done: function (res) {
                            if (res.code == "0") {
                                layer.alert("导入成功！");
                                RenderData(2);
                            } else {
                                layer.alert("上传失败" + res.msg);
                            }
                        }
                        , error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest.status + ' ' + textStatus + ' (' + errorThrown + ')');
                        }
                    });
                //上传数据
                upload.render({ //允许上传的文件后缀
                    elem: '#doImporttpz'
                    , url: '/GroupChoseDrugCompare/ImportVarietyDrug'//此处配置你自己的上传接口即可
                    , accept: 'file' //普通文件
                    , exts: 'xls|xlsx' //只允许上传表格文件
                    , auto: false//不自动上传
                    , bindAction: '#Importtpz'
                    , before: function () {
                        this.data = {
                            gpCode: $("#GroupPurchase").val()
                        }
                    }

                    , done: function (res) {
                        if (res.code == "0") {
                            layer.alert("导入成功！");
                            RenderData(2);
                        } else {
                            layer.alert("上传失败" + res.msg);
                        }
                    }
                    , error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status + ' ' + textStatus + ' (' + errorThrown + ')');
                    }
                });

                $('#doDownloadfzx').on('click', function () {
                    var form = document.createElement('form');
                    form.action = '/GroupChoseDrugCompare/ImportTempletFzx';
                    form.method = 'post';
                    $(document.body).append(form);
                    form.submit();
                });
                $('#doDownloadtpz').on('click', function () {
                    var form = document.createElement('form');
                    form.action = '/GroupChoseDrugCompare/ImportTempletTpz';
                    form.method = 'post';
                    $(document.body).append(form);
                    form.submit();
                });
                $('#export').on('click', function () {
                    var gpcode = $("#GroupPurchase").val();
                    if (gpcode == "") {
                        alert("请先选择集采批次");
                        return;
                    }
                    var form = document.createElement('form');
                    form.action = '/GroupChoseDrugCompare/export?gpcode=' + gpcode;
                    form.method = 'post';
                    $(document.body).append(form);
                    form.submit();
                });
            function RenderData(type) {

                var gpcode = $("#GroupPurchase").val();
                var drugcode = $("#drugCode").val();
                var isset = $("#set").val();
                if (type == "2") {

                    if (gpcode == "") {
                        alert("请先选择集采批次");
                        return;
                    }

                }


                table.render({
                    elem: '#LAY-dept-list'
                    , url: '/GroupChoseDrugCompare/GetList?gpCode=' + gpcode + '&drugCode=' + drugcode + "&isSet=" + isset//模拟接口
                    , toolbar: '#table-toolbar'
                    , method: 'post'
                    , cols: [[
                        { field: 'GpCode', title: '集采批次编码', width: 150 }
                        , { field: 'GpName', title: '批次名称', width: 200 }
                        , { field: 'Year', title: '年度', width: 80 }
                        , { field: 'BeginDate', title: '开始日期', width: 120 }
                        , { field: 'EndDate', title: '结束日期', width: 120 }
                        , { field: 'ChosedrugCode', title: '中选药品编码', width: 140 }
                        , { field: 'ChosedrugName', title: '中选药品名称', width: 250 }
                        , { field: 'Specs', title: '规格', width: 150 }
                        , { field: 'ProducerName', title: '生产厂家', width: 200 }
                        , { field: 'Enabled', title: '是否启用', width: 120, hide: true }
                        //, { field: 'OperCode', title: '操作人', width: 100 }
                        //, { field: 'OperDate', title: '操作时间', width: 120 }
                        , { field: 'right', title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#barBtn' }
                    ]]
                    , page: true
                    , limit: 10
                    , limits: [10, 15, 20, 25, 30]
                    , text: { none: '暂无数据' }
                });
            }

        });
    </script>
